#include <stdbool.h>
#include "uthash.h"

extern FILE *yyin, *yyout;

extern int yylineno;

void yyerror(char *s);

struct symbol {
    int value;
    char *name;
    UT_hash_handle hh;
};

struct astree {
    int nodetype;
    struct astree *left;
    struct astree *right;
};

struct statement_list {
    struct astree *exp;
    struct statement_list *next;
};

struct numeric {
    int nodetype;
    int value;
};

struct varname {
    char *name;
    int length;
    struct astree *function;
};

struct arguments {
    struct varname *vn;
    struct arguments *next;
};

struct symbol *symbol_table;

struct symbol *get_symbol(char *name);

struct symbol *add_symbol(char *name, int value);

struct astree *init_number(int i);

struct astree *build_ast(struct astree *left, struct astree *right, int nodetype);

struct astree *get_ast(struct symbol *sym);

int evaluate_ast(struct astree *ast);

char *substring(char *string, int length);

struct astree *symbol_to_expression(struct varname *vn);

void assignment(struct varname *vn, struct astree *ast);

struct astree *function_call(struct varname *function, struct arguments *argm);

void define_function(struct varname *function_name, struct varname *argument, struct astree *statements);

struct statement_list *store_expression(struct astree *ast);

struct arguments *bind_arguments(struct varname *vn, struct arguments *ar);

struct astree *evaluate_condition(bool con, struct astree *if_statement, struct astree *else_statement);

bool init_condition(struct astree *first, int logical_type, struct astree *second);

struct astree *negate_ast(struct astree *ast);
